package $NAMESPACE.persistence.entity.handler;

import $NAMESPACE.common.enums.XXXEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class XXXEnumTypeHandler extends BaseTypeHandler<XXXEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, XXXEnum t, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, t.getCode());
    }

    @Override
    public XXXEnum getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return XXXEnum.valueOf(resultSet.getInt(s));
    }

    @Override
    public XXXEnum getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return XXXEnum.valueOf(resultSet.getInt(i));
    }

    @Override
    public XXXEnum getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return XXXEnum.valueOf(callableStatement.getInt(i));
    }
}